<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">
            <!-- 放置表单 -->
            <el-form :model="settingData" :rules="rules" label-width="120px" style="margin-left: 120px; margin-top:30px">
              <el-form-item label="姓名:" prop="username">
                <el-input v-model="settingData.username" style="width:300px" />
              </el-form-item>
              <el-form-item label="密码:" prop="password2">
                <el-input v-model="settingData.password2" style="width:300px" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="updata">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <user-info />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <job-info />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getUserDetail } from '@/api/user'
import { saveUserDetailById } from '@/api/employee'
import userInfo from './userinfo.vue'
import jobInfo from './jobinfo.vue'
export default {
  components: {
    userInfo,
    jobInfo
  },
  data() {
    return {
      // 账户信息
      settingData: {
        username: '',
        password2: ''
      },
      // 账户表单校验
      rules: {
        username: [
          { required: true, message: '该项不可为空', trigger: 'blur' }
        ],
        password2: [
          { required: true, message: '该项不可为空', trigger: 'blur' },
          { min: 6, max: 8, message: '密码长度在 6 到 8 个数字', trigger: 'blur' }
        ]
      }
    }
  },
  async mounted() {
    // 表单回填数据
    const res = await getUserDetail(this.$route.params.id)
    this.settingData = res
  },
  methods: {
    // 更新按钮
    async updata() {
      this.settingData.password = this.settingData.password2
      await saveUserDetailById(this.settingData)
      this.$message.success('更新成功')
    }
  }
}
</script>

<style>

</style>
